//salary.js
//获取应用实例
const app = getApp()
/**
 * 版权：山西书海传媒科技有限责任公司
 * 作者：吕俊雄
 * 更新时间：2019年3月29号
 */
Page({
  data: {
    date: '请选择时间',
    datea: ''
  },
  onLoad: function (options) {
    var that = this;
    wx.request({
      url: 'https://wxapp.shuhai.cc/hh/querySalary.action',
      method: 'post',
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      data: {
        parayId: wx.getStorageSync("shuhai_party_id"),
        months: ''
      },
      success: function (res) {
        console.log(res.data);
        that.setData({
          salary: res.data.data.lists,
          months: res.data.data.months,
          name: res.data.data.name
        })
      }
    });
  },
  bindDateChange(e) {
    console.log('picker发送选择改变，携带值为', e.detail.value);
    var that = this;

    var ths="";
    wx.request({
      url: 'https://wxapp.shuhai.cc/hh/changeTime.action',
      method: 'post',
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      data: {
        c_time: e.detail.value,
      },
      success: function (res) {
        console.log(res.data.data.result + "=====获取到的年月");
        ths = res.data.data.result    
        //展示加载中
        // wx.showLoading({
        //   title: '加载中',
        // })
        wx.request({
          url: 'https://wxapp.shuhai.cc/hh/clickLog.action',
          method: 'post',
          data: {
            type: '11',
            userid: wx.getStorageSync("userOpenid"),
            content: '查看了' + res.data.data.result + '的工资条'
          },
          header: {
            'content-type': 'application/x-www-form-urlencoded'
          },
          success: function (res) {
            console.log("======开始");

            wx.request({
              url: 'https://wxapp.shuhai.cc/hh/querySalary_ss.action',
              method: 'post',
              header: {
                'content-type': 'application/x-www-form-urlencoded'
              },
              data: {
                parayId: wx.getStorageSync("shuhai_party_id"),
                //parayId: '374b8c0569c30a040169c347994901df',
                months: ths,
              },
              success: function (res) {
                console.log(res.data);
                console.log(">>>>>>>>>."+wx.getStorageSync("shuhai_party_id"));
               
                if (res.data.status == "success") {
                  //隐藏加载中
                  wx.hideLoading();
                  that.setData({
                    salary: res.data.data.lists,
                    months: res.data.data.months,
                    name: res.data.data.name
                  })
                }
              },
              fail: function (res) {
                wx.hideLoading();
                wx.showToast({
                  title: '网络错误！',
                  icon: 'none',
                  duration: 2000
                })
                return;
              }
            });
          }
        });
        console.log("======结束");
        that.setData({
          date: res.data.data.result
        })
      }
    });
  },
  goQuery: function (e) {
    var that = this;
    //展示加载中
    wx.showLoading({
      title: '加载中',
    })
    wx.request({
      url: 'https://wxapp.shuhai.cc/hh/clickLog.action',
      method: 'post',
      data: {
        type: '11',
        userid: wx.getStorageSync("userOpenid"),
        content: '查看了' + that.data.date + '的工资条'
      },
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      success: function (res) {
    wx.request({
      url: 'https://wxapp.shuhai.cc/hh/querySalary_ss.action',
      method: 'post',
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      data: {
        parayId: wx.getStorageSync("shuhai_party_id"),
        //parayId: '374b8c0569c30a040169c347994901df',
        months: that.data.date
      },
      success: function (res) {
        console.log(wx.getStorageSync("shuhai_party_id"));
        console.log(that.data.date);
        if (res.data.status == "success") {
          //隐藏加载中
          wx.hideLoading();
          that.setData({
            salary: res.data.data.lists,
            months: res.data.data.months,
            name: res.data.data.name
          })
        }
      },
      fail: function (res) {
        wx.hideLoading();
        wx.showToast({
          title: '网络错误！',
          icon: 'none',
          duration: 2000
        })
        return;
      }
    });
      }
    });
  }
})